﻿using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

namespace ExameRegister.Model
{
    public class DataEntity : INotifyPropertyChanged
    {
        private bool _IsValidate = false;

        public bool IsValidate
        {
            get { return _IsValidate; }
            set { _IsValidate = value; }
        }

        public virtual void Validate(string PropName, object value, object instance)
        {
            if (IsValidate)
                Validator.ValidateProperty(value, new ValidationContext(instance, null, null) { MemberName = PropName });
            OnPropertyChanged(PropName);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(string propName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
            }
        }
    }
}
